package com.android.common.network;

import android.net.ConnectivityManager;
import android.net.Network;
import androidx.annotation.NonNull;

public class CustomNetworkCallback extends ConnectivityManager.NetworkCallback {

    private static final CustomNetworkCallback mInstance = new CustomNetworkCallback();
    private NetworkConnectListener mListener;

    public static CustomNetworkCallback getInstance(){
        return mInstance;
    }

    @Override
    public void onAvailable(@NonNull Network network) {
        super.onAvailable(network);
        if (mListener != null){
            mListener.onNetworkAvailable(network);
        }
    }

    @Override
    public void onUnavailable() {
        super.onUnavailable();
        if (mListener != null){
            mListener.onNetworkUnavailable();
        }
    }

    @Override
    public void onLost(@NonNull Network network) {
        super.onLost(network);
        if (mListener != null){
            mListener.onNetworkLost(network);
        }
    }

    public void setListener(NetworkConnectListener listener) {
        mListener = listener;
    }
}
